package com.example.mongo.controller;

import com.example.mongo.Model.bean.Chapter;
import com.example.mongo.Model.bean.Menu;
import com.example.mongo.Model.bean.User;
import com.example.mongo.Model.dto.ComicItemDto;
import com.example.mongo.Model.dto.ResponseData;
import com.example.mongo.dao.UserMapper;
import com.example.mongo.service.ChapterService;
import com.example.mongo.service.MenuService;
import com.example.mongo.service.UserService;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/chapter")
public class ChapterController {
    @Autowired
    ChapterService chapterService;
    @Autowired
    ResponseData responseData;
    @Autowired
    MenuService menuService;


    @RequestMapping(value = "/getChapterByChapterId/{chapterId}",produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
    public String getChapterByChapterId(@PathVariable("chapterId")int chapterId){
        Chapter chapter = chapterService.getChapterByChapterId(chapterId);
        if(null==chapter){
            responseData.error("400","章节不存在","");
        }else {
            responseData.success("ok", JSONObject.fromObject(chapter).toString());
        }
        return responseData.toString();
    }

    //    /test/updatePassword?userName=12312&userPasswword=ming
    @RequestMapping(value = "/getChapterByComicId/{comicId}",produces = "application/json;charset=UTF-8",method = RequestMethod.GET)
    public String getChapterByComicId(@PathVariable("comicId")int comicId){
        ComicItemDto   comicItemDto = chapterService.getComicByComicId(comicId);
        if(null == comicItemDto){
            responseData.error("400","漫画不存在","");
        }else {
            responseData.success("ok",comicItemDto.toString());
        }
        return responseData.toString();
    }




}
